interface Person {
    name: string;
    age: number;
    gender: string;
    sayHello(): void;
}

function sayHello(person: Person) {
    console.log(`Hello, ${person.name}`);
}

sayHello({ name: 'Alice', age: 30, gender: 'female', sayHello: () => console.log('Hello!') }); // Hello, Alice

// interface 与 type 的区别：
/* 
interface Animal {
    name: string
}

interface Dog extends Animal {
    bone: string
}

const dog: Dog = {
    name: 'Buddy',
    bone: 'Big Bone'
}

console.log(dog.name); // Buddy
console.log(dog.bone); // Big Bone


type Animal = {
    name: string
}

type Dog = Animal & {
    bone: string
}

const dog: Dog = {
    name: 'Buddy',
    bone: 'Big Bone'
}

console.log(dog.name); // Buddy
console.log(dog.bone); // Big Bone */


// 向现有的类型添加字段
/* interface myWindow {
    title: string
}

interface myWindow {
    url: string
}

const w: myWindow = {
    title: 'TypeScript',
    url: 'https://www.typescriptlang.org'
} // title 和 url 都存在
 */

type myWindow = { title: string } & { url: string }